package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.OrderRefund;
import com.qf.entity.OrderRefundDTO;
import com.qf.entity.OrderRefundVO;
import com.qf.service.OrderRefundService;
import com.qf.service.OrderRefundVOService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 天--道--酬--勤
 *
 * @author LiangGaoQiang
 * @ClassName OrderRefundController
 * @Date: 2025/4/30 15:39
 * @Description: 描述
 */
@RestController
@RequestMapping("/orderRefundVO")
public class OrderRefundVOController {
    @Autowired
    private OrderRefundVOService orderRefundVOService;

    @GetMapping("/pageV2")
    public R orderRefundPage(OrderRefundDTO orderRefundDTO) {
        // 第一步：开启分页插件
        PageHelper.startPage(orderRefundDTO.getPageNum(), orderRefundDTO.getPageSize());

        // 第二步：查询所有退款信息列表
        List<OrderRefundVO> orderRefundVOList = orderRefundVOService.queryAllOrderRefundVO(orderRefundDTO);

        // 第三步：封装分页信息
        PageInfo<OrderRefundVO> pageInfo = new PageInfo<>(orderRefundVOList);

        // 第四步：封装返回结果
        return R.ok(pageInfo);
    }


    /**
     * 添加订单
     * @param orderRefund 订单实体类
     * @return 添加结果
     */
    @PostMapping("/addRefundV2")
    public R addOOrderRefund(@RequestBody OrderRefund orderRefund) {
        boolean result = orderRefundVOService.addOrderRefundVO(orderRefund);
        // 判断是否添加成功
        if (result) {
            return R.ok();
        }
        return R.fail();
    }

}
